package com.base.common.base.mvvm;

import androidx.databinding.ViewDataBinding;

import com.base.common.base.delegate.CustomRegisterDelegate;
import com.base.common.net.loading.DialogLoading;
import com.base.library.base.Loading;
import com.base.library.base.delegate.RegisterSDKDelegate;
import com.base.library.base.delegate.StatusView;
import com.base.common.base.delegate.StatusViewRefreshDelegate;
import com.base.library.base.mvvm.BaseListVActivity;
import com.base.library.base.mvvm.BaseViewModel;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;

/**
 * @Date: 2019/10/25 16:27
 * @Author: Jayden
 * @Description:
 * @Version:
 */
public abstract class BaseNormalListVActivity<VM extends BaseViewModel, V extends ViewDataBinding>
        extends BaseListVActivity<VM, V> {

    @Override
    protected StatusView onCreateStatusView() {
        return new StatusViewRefreshDelegate()
                .setRefreshLoadMoreListener(this)
                .setStateViewClickListener(this);
    }

    @Override
    protected RegisterSDKDelegate onCreateRegisterSDKDelegate() {
        return new CustomRegisterDelegate(this)
                .setBindEventBusHere(isBindEventBusHere());
    }

    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    public Loading getLoading() {
        if (loading == null) {
            loading = new DialogLoading(getActivity(), false);
        }
        return loading;
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        return (BaseQuickAdapter) adapter;
    }

    @Override
    protected void replaceData(List items) {
        if (getAdapter() != null) {
            getAdapter().setNewData(items);
        }
    }

    @Override
    protected void addData(List items) {
        if (getAdapter() != null) {
            getAdapter().addData(items);
        }
    }

    @Override
    protected List getData() {
        return getAdapter() != null ?
                getAdapter().getData() : null;
    }

}
